﻿using System;
using System.ComponentModel;
using Wizard.UI;

namespace AppScan
{
    public partial class PasswordPage : InternalWizardPage
    {
        private readonly CreateUserContext _context;

        public PasswordPage(CreateUserContext context)
        {
            _context = context;

            InitializeComponent();
        }

        private void passwordTextBox_TextChanged(object sender, EventArgs e)
        {
            EnableControls();
        }

        private void confirmPasswordTextBox_TextChanged(object sender, EventArgs e)
        {
            EnableControls();
        }

        private void EnableControls()
        {
            if (radioButton1.Checked)
                SetWizardButtons(WizardButtons.Back | WizardButtons.Next);
            else
            {
                if (!string.IsNullOrEmpty(passwordTextBox.Text) && (!string.IsNullOrEmpty(Username_txt.Text)))
                    SetWizardButtons(WizardButtons.Back | WizardButtons.Next);
                else
                    SetWizardButtons(WizardButtons.Back);
            }
        }

        private void PasswordPage_SetActive(object sender, CancelEventArgs e)
        {
            EnableControls();
        }

        private void PasswordPage_WizardNext(object sender, WizardPageEventArgs e)
        {
            //_context.ShowAdvancedPasswordOptions = editAdvancedPasswordOptionsCheckBox.Checked;

            //if (_context.ShowAdvancedPasswordOptions)
            //   e.NewPage = "AdvancedPasswordOptionsPage";
            //else
            if (radioButton2.Checked)
            {
                _context.domain = Domain_txt.Text;
                _context.username = Username_txt.Text;
                _context.password = passwordTextBox.Text;
            }
            else
            {
                _context.domain = "";
                Username_txt.Text = @"$using current credentials";
                passwordTextBox.Text =@"$using current credentials";
                _context.username = @"$using current credentials";
                _context.password = @"$using current credentials";
            }
                //e.NewPage = "SummaryPage";
            e.NewPage ="ScanOptionsPage";
        }

        private void editAdvancedPasswordOptionsCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (editAdvancedPasswordOptionsCheckBox.Checked)
            {
                passwordTextBox.UseSystemPasswordChar = false;
            }
            else
            {
                passwordTextBox.UseSystemPasswordChar = true;
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (!(radioButton2.Checked))
            {
                EnableControls();
                //get current creds to impersonate
                radioButton2.Checked = false;
                Domain_txt.Enabled = false;
                Domain_txt.BackColor = System.Drawing.SystemColors.Control;
                Username_txt.Enabled = false;
                Username_txt.BackColor = System.Drawing.SystemColors.Control;
                passwordTextBox.Enabled = false;
                passwordTextBox.BackColor = System.Drawing.SystemColors.Control;
                editAdvancedPasswordOptionsCheckBox.Enabled = false;
                editAdvancedPasswordOptionsCheckBox.BackColor = System.Drawing.SystemColors.Control;
            }
        }

        private void getCred()
        {

        
        
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                Domain_txt.Enabled = true;
                Domain_txt.BackColor = System.Drawing.SystemColors.Window;
                Username_txt.Enabled = true;
                Username_txt.BackColor = System.Drawing.SystemColors.Window;
                passwordTextBox.Enabled = true;
                passwordTextBox.BackColor = System.Drawing.SystemColors.Window;
                editAdvancedPasswordOptionsCheckBox.Enabled = true;
                //editAdvancedPasswordOptionsCheckBox.BackColor = System.Drawing.SystemColors.Window;
            }
        }
    }
}
